<?php
/**
 * Created by PhpStorm.
 * User: zengyuming
 * Date: 2017/8/15
 * Time: 下午4:38
 */

namespace Admin\Controller;
class TransactionController extends CommonController {
    public function Index(){
        $modelobj = new \Admin\Model\transactionModel();
        $count = M('transaction')->where($modelobj->transactionSearch())->count();
        $page_obj = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $data = M('transaction')
            ->alias('a')
            ->field('a.* , b.Userremarks as gamaname')
            ->join('left join zym_user as b on a.merchant = b.merchant_id')
            ->where($modelobj->transactionSearch())
            ->limit($page_obj->firstRow . ',' . $page_obj->listRows)
            ->order("id desc")
            ->select();
//        var_dump($data);die;
        $page_obj->lastSuffix = false;
        $page_obj->setConfig('prev','上一页');
        $page_obj->setConfig('next','下一页');
        $page_obj -> setConfig('first','首页');
        $page_obj -> setConfig('last','尾页');
    //    $page_obj -> setConfig('theme','%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
        $page_str   = $page_obj->show();// 分页显示输出
        $passagewayInfo = M("payinfo")->query("select *,CASE pay_type 
         WHEN 'WeixinScancode' THEN '微信扫码' 
         WHEN 'qq_pay' THEN 'QQ支付' 
         WHEN 'alipay_pay' THEN '支付宝' 
         WHEN 'weixinGzh_pay' THEN '微信公众号'
         WHEN 'jd_pay' THEN '京东钱包'
         WHEN 'bank_Pay' THEN '网银支付'
         END as name from zym_payinfo;");

        /* 按平台搜索 */
        $MerchantPingtai = M("user")->field('merchant_id,Userremarks')->select();
        $this->assign('platforms' , $MerchantPingtai);
        /* 按平台搜索 The End */

        $passageway = explode('@' , $_GET['passageway']);
        $this->assign('passageway' , $passageway);
        $this->assign('pay_passagewayS' , $passagewayInfo);
        $this->assign('page',$page_str);// 赋值分页输出
        $this->assign('datas' , $data);
        $this->assign('current_Titlename' , '交易记录');
        $this->display('Index');
    }

    public function repCallback(){
        $order_number = I("post.order_number");
        $myKey1 = '95444015d88928b07abd8d6f93f0cb5b';
        $res = A("Notify")->ReplayPayCallback($order_number , $myKey1);
        if(empty($order_number) || $order_number == ''){
            exit(json_encode(array('msg' => '订单号错误' , 'code' => 4)));
        }

        if($res == 1){
            echo json_encode(array('msg' => '该订单充值不成功，补单失败！' , 'code' => 1));
            exit();
        }

        if($res == 2){
            exit(json_encode(array('msg' => '订单补单失败，可能已经成功了！' , 'code' => 2)));
        }

        if($res === 3) {
            // 成功补单
            exit(json_encode(array('msg' => '订单补单成功，成功订单号' . $order_number, 'code' => 3)));
        }else{
            exit('hello word');
        }

    }
}